<script setup>
import {inject, onMounted, ref, watch, defineProps} from "vue";

const props = defineProps({
  height: '100%'
})
const code = inject('stockCode')
const market = ref('1')
const stockCode = ref('000001')

watch(code, ()=> {
  setCode()
})

const setCode = () => {
  if (code.value === '000000') {
    market.value = '1'
    stockCode.value = '000001'
  } else {
    stockCode.value = code.value
    if (code.value.startsWith('6')) {
      market.value = '1'
    } else {
      market.value = '2'
    }
  }

}

setCode()

</script>

<template>
  <iframe id="iframeStock" :style="{height}"
          :src="`https://quote.eastmoney.com/basic/h5chart-iframe.html?code=${stockCode}&market=${market}&type=r`"></iframe>
</template>
<style scoped>
#iframeStock {
  width: 100%;
  height: 100%;
  border: 0;
  background-color: #FFFFFF;
}
</style>
